package edu.cs.usask.ca.silver.api.businesslogic;

import java.io.File;
import java.util.Map;

import edu.cs.usask.ca.silver.api.persistence.StorageI;
import edu.cs.usask.ca.silver.businesslogic.ids.ScenarioID;
import edu.cs.usask.ca.silver.exceptions.UnableToInitializeStorageException;
import edu.cs.usask.ca.silver.exceptions.VensimLogicErrorException;

/**
 * 
 * The interface specification for both local and remote implementations of the
 * SilverService bean. This bean takes care of some of the more general tasks in
 * Silver that are not related to a particular model object (Project, Version,
 * etc.)
 * 
 * @author Yudi Xue, Daniel Funk
 */
public interface SilverServiceI {

	/**
	 * 
	 * @param databaseLoc
	 * @param user
	 * @param pass
	 * @param poolSize
	 * @param connTimeOut
	 * @return
	 * @throws InvalidDatabaseException
	 *             , Exception
	 */
	public StorageI getLocalDerbyStorage(String databaseLoc, String user,
			String pass, int poolSize, int connTimeOut)
			throws UnableToInitializeStorageException, Exception;

	/**
	 * 
	 * @param serverLoc
	 * @param databaseName
	 * @param port
	 * @param user
	 * @param pass
	 * @param poolSize
	 * @param connTimeOut
	 * @return
	 * @throws InvalidDatabaseException
	 *             , Exception
	 */
	public StorageI getRemoteDerbyStorage(String serverLoc,
			String databaseName, int port, String user, String pass,
			int poolSize, int connTimeOut) throws UnableToInitializeStorageException,
			Exception;

	/**
	 * PgSQL is temporarily unsupported due to lack of transaction support from
	 * Atomikos Transaction Essentials.
	 * 
	 * @param serverLoc
	 * @param databaseName
	 * @param port
	 * @param user
	 * @param pass
	 * @param poolSize
	 * @param connTimeOut
	 * @return
	 * @throws Exception
	 */
	@Deprecated
	public StorageI createPgSqlStorage(String serverLoc, String databaseName,
			int port, String user, String pass, int poolSize, int connTimeOut)
			throws Exception;

	/**
	 * Runs a specified scenario simulation and take screenshot of simulation
	 * result
	 * 
	 * @param sId
	 *            The unique scenario identifier of the scenario to be run
	 * @param storage
	 *            The database instance used to extract data from
	 * @throws Exception
	 */
	public void runAnylogicScenarioScreenShot(ScenarioID sId,
			String anylogicPath, StorageI storage) throws Exception;

	/**
	 * Runs a specified scenario simulation and execute runtime logging.
	 * 
	 * @param sId
	 *            The unique scenario identifier of the scenario to be run
	 * @param anylogicPath
	 *            The path to Anylogic on file disk
	 * @param storage
	 *            The database instance used to extract data from
	 * @throws Exception
	 */
	public void runAnylogicScenarioLogging(ScenarioID sId, String anylogicPath,
			StorageI storage) throws Exception;

	/**
	 * Runs a specified scenario simulation with out any modification.
	 * 
	 * @param sId
	 *            The unique scenario identifier of the scenario to be run
	 * @param storage
	 *            The database instance used to extract data from
	 * @throws Exception
	 */
	public void runAnylogicScenario(ScenarioID sId, String anylogicPath,
			StorageI storage) throws Exception;

	/**
	 * Runs a specified Vensim scenario simulation with defiend values
	 * 
	 * @param sId
	 *            The unique scenario identifier of the scenario to be run
	 * @param simName
	 *            Name of the Vensim simulation for Vensim interface.
	 * @param storage
	 *            The database instance used to extract data from
	 * @throws Exception
	 */
	public void runVensimScenario(ScenarioID sId, String simName,
			StorageI storage) throws Exception;

	// extracts parameter values from a pdf.
	// TODO: should this really be located in this interface?

	// We'd ideally like to return a Map<ParameterID, Double> , but this was
	// causing a bizarre error
	// where the hash table wasn't working (see
	// CreateScenarioTableContentProvider)

	public Map<Integer, Double> ExtractValuesForParametersFromVDFTrajectoryFile(
			ScenarioID scenarioId, File addFile, StorageI storage)
			throws Exception, VensimLogicErrorException;

	public boolean loadVenDll(String libPath) throws Exception;

	public boolean vensimLibIsLoaded();

}
